package com.numberone.web.controller.assess;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.numberone.common.annotation.Log;
import com.numberone.common.enums.BusinessType;
import com.numberone.system.domain.Assess;
import com.numberone.system.service.IAssessService;
import com.numberone.framework.web.base.BaseController;
import com.numberone.common.page.TableDataInfo;
import com.numberone.common.base.AjaxResult;
import com.numberone.common.utils.poi.ExcelUtil;

/**
 * 商品评价 信息操作处理
 * 
 * @author numberone
 * @date 2020-10-13
 */
@Controller
@RequestMapping("/system/assess")
public class AssessController extends BaseController
{
    private String prefix = "system/assess";
	
	@Autowired
	private IAssessService assessService;
	
	@RequiresPermissions("system:assess:view")
	@GetMapping()
	public String assess()
	{
	    return prefix + "/assess";
	}
	
	/**
	 * 查询商品评价列表
	 */
	@RequiresPermissions("system:assess:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Assess assess)
	{
		startPage();
        List<Assess> list = assessService.selectAssessList(assess);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商品评价列表
	 */
	@RequiresPermissions("system:assess:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Assess assess)
    {
    	List<Assess> list = assessService.selectAssessList(assess);
        ExcelUtil<Assess> util = new ExcelUtil<Assess>(Assess.class);
        return util.exportExcel(list, "assess");
    }
	
	/**
	 * 新增商品评价
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商品评价
	 */
	@RequiresPermissions("system:assess:add")
	@Log(title = "商品评价", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Assess assess)
	{		
		return toAjax(assessService.insertAssess(assess));
	}

	/**
	 * 修改商品评价
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		Assess assess = assessService.selectAssessById(id);
		mmap.put("assess", assess);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商品评价
	 */
	@RequiresPermissions("system:assess:edit")
	@Log(title = "商品评价", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Assess assess)
	{		
		return toAjax(assessService.updateAssess(assess));
	}
	
	/**
	 * 删除商品评价
	 */
	@RequiresPermissions("system:assess:remove")
	@Log(title = "商品评价", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(assessService.deleteAssessByIds(ids));
	}
	
}
